﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer.Properties;
using System.Transactions;
using IMModel.Domain;

namespace DataAccessLayer.Admin.Copy.IndexMarkStruct
{
    public class GradationCopy : ICopy
    {
        public int Copy(int IDCopiedObject, int? IDParentObject, int fromIDTerm, int toIDTerm)
        {
            using (IMModel.Domain.IMDataDataContext db = new IMModel.Domain.IMDataDataContext(Settings.Default.IndexMarkConnectionString))
            {
                GradationTerm old = db.GradationTerms.Single(s => s.IDGradationTerm == IDCopiedObject);

                GradationTerm _new = new GradationTerm
                {
                    IDGradation = old.IDGradation,
                    IDParentGradationTerm = IDParentObject,
                    IDTerm = toIDTerm,
                    Order = old.Order,
                    Weight = old.Weight
                };

                db.GradationTerms.InsertOnSubmit(_new);
                db.SubmitChanges();

                return _new.IDGradationTerm;
            }
        }
    }
}
